package org.example.controller;

import io.swagger.annotations.Api;
import org.example.config.Result;
import org.example.domain.SysDictData;
import org.example.domain.SysDictType;
import org.example.service.SysDictDataService;
import org.example.service.SysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Api(tags = {"字典数据接口"})
@RestController
@RequestMapping("sysDictData")
public class SysDictDataController {

    @Autowired
    private SysDictDataService sysDictDataService;

    @Autowired
    private SysDictTypeService sysDictTypeService;

    @RequestMapping("list")
    public Result list(SysDictData sysDictData){
        List<SysDictData> list = sysDictDataService.list(sysDictData);

        return Result.success(list);
    }

    @RequestMapping("type")
    public Result type(){
        List<SysDictType> list = sysDictTypeService.list();
        return Result.success(list);
    }

    @RequestMapping("add")
    public Result add(SysDictData sysDictData){

        sysDictData.setRemark("aaaaaa");
        sysDictData.setCreateTime(new Date());

        return Result.success(sysDictDataService.add(sysDictData));
    }

    @RequestMapping("delete")
    public Result delete(SysDictData sysDictData){

        return Result.success(sysDictDataService.delete(sysDictData));
    }

    @RequestMapping("update")
    public Result update(SysDictData sysDictData){

        return Result.success(sysDictDataService.update(sysDictData));
    }

    @RequestMapping("deAll")
    public Result deAll(Long[] id){

        return Result.success(sysDictDataService.deAll(Arrays.asList(id)));
    }

}
